<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="__STATIC__/css/screen.css" media="screen" />
    <link rel="stylesheet" href="__STATIC__/css/print.css" media="print" />
    <title>学员信息拍照录入</title>
    <script language="javascript" type="text/javascript" src="__STATIC__/js/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="__STATIC__/js/jquery-migrate-1.2.1.min.js"></script>
    <script language="javascript" type="text/javascript" src="__STATIC__/js/jquery.jqprint.js"></script>
    <style>
        #action{
            text-align: center;
        }
    </style>
    <style>
        #table_box{margin:0 auto;margin-left: 0px;}
        #pic_box{float:left;margin-right:0px;}
        .line1{margin:15px 0px;}
        #mask{background-color:#333;width:320px;;position:absolute;top:50%;left:40%;
        padding:30px 20px;border-radius:5px;color:#fff;filter:Alpha(opacity=80);display:none;}
        select{height:22px;border:1xp solid #ccc;}
        #retime{color:red;}
    </style>
</head>
<body>
    <div id="pic_box" style="height:30cm;border-right:1px solid #ccc;padding-right:15px;width:853px;margin-right: 20px;">
        <div>
            <img id="firstVideo" src="http://127.0.0.1:38088/video=stream&camidx=0" width="400px" height="300px" alt="视频预览">
            <img id="secondVideo" src="http://127.0.0.1:38088/video=stream&camidx=1" width="400px" height="300px" alt="视频预览">
        </div>
        <div>
             <img id="firstResImg" src="" width="400" height="150">
             <img id="secondResImg" src="" width="400" height="150"> 
        </div>
        <tr>
            <td>
                <div class="line1">
                <label id="lab1">主摄像头</label>
                <select id="subType1" style="width: 90px" name="subType1"">
                    <option>主摄像头</option>
                </select> 
                <select id="selRes1" style="width: 90px" name="selRes">
                    <option>MJPG</option>
                </select> 
                分辨率<select id="resolutionFirst" style="width: 90px">          
                </select> 
                <label id="lab2">副摄像头</label>
                <select id="subType2" style="width: 90px" name="subType2" onchange="changesubTypeAssist()">
                    <option>副摄像头</option>
                </select> 
                 <select id="selRes2" style="width: 90px" name="selRes2">
                    <option>MJPG</option>
                </select>
                分辨率<select id="resolutionSecond" style="width: 90px" name="selRes"></select>        
                
                  
                </div>
                <input class="submit_01" type="hidden" value="上传本地文件"   onclick="UploadToHttpServer()" />
                <input class="submit_01" type="button" value="打开摄像头" onclick="openAll()" style="border:none;padding:10px 5px;background-color:#ccc;font-size:12px;"/>
                <input class="submit_01" type="button" value="关闭摄像头" onclick="CloseCamera()" style="border:none;padding:10px 5px;background-color:#ccc;font-size:12px;"/>
                <b>|</b>
                身份信息填写方式<select id="info_method" style="width: 90px;margin-left:5px;" name="info_method" >          
                    <option value ="baidu">百度算法</option>
                    <option value="manual">手动填写</option>
                </select> 
                <!--<input id="EnableDate" type="checkbox" value="" onclick="EnableDate(this)" />日期
                <input id="AddText" type="checkbox" value="" onclick="AddText(this)" />文字-->
                <input id="Deskew" type="checkbox" value="" onclick="Deskew(this)" />纠偏
                <input id="SetState" type="checkbox" value="" onclick="SetState(this)" />手动框选

                <div style="display:none;">
                <input id="OpenVerifyFacRect" type="checkbox" value="" onclick="OpenVerifyFacRect(this)" />脸部裁剪 
                <br />
                <input class="submit_01" type="button" value="左转"   onclick="Left()" />
                <input class="submit_01" type="button" value="右转"   onclick="Right()" />
                <input class="submit_01" type="button" value="属性"   onclick="ShowProperty()" />
                <b>|</b>
                <input class="submit_01" type="button" value="主头录像" onclick="StartMainRecord()" />
                <input class="submit_01" type="button" value="停止"   onclick="StopMainRecord()" />
                <input class="submit_01" type="button" value="副头录像" onclick="StartAssistRecord()" />
                <input class="submit_01" type="button" value="停止"   onclick="StopAssistRecord()" />     
                <b>|</b>
                <input class="submit_01" type="button" value="缩略图多张上传"  onclick="UploadThumbToServer()" />
                <input class="submit_01" type="button" value="上传本地文件"   onclick="UploadToHttpServer()" />
                <input class="submit_01" type="button" value="扫描直接上传"   onclick="ScanToHttpServer()" />
                <b>|</b>
                <input class="submit_01" type="button" value="条码/二维码识别" onclick="Barcode()" />
                <input class="submit_01" type="button" value="MD5" onclick="GetImgMD5()" />
                <input class="submit_01" type="button" value="OCR" onclick="OCR()" />
                <br />
                <input class="submit_01" type="button" value="初始化"  onclick="InitBiokey()" />
                <input class="submit_01" type="button" value="采集指纹特征"   onclick="GetFeature()" />
                <img src=""  id="BiokeyImg2" alt="指纹图像2" width=20 height=20/>
                <input class="submit_01" type="button" value="停止采集特征"   onclick="StopGetFeature()" />
                <input class="submit_01" type="button" value="采集指纹模板"   onclick="GetTemplate()" />
                <img src=""  id="BiokeyImg1" alt="指纹图像1" width=20 height=20/>
                <input class="submit_01" type="button" value="停止采集模板"   onclick="StopGetTemplate()" />
                <input class="submit_01" type="button" value="指纹对比" onclick="BiokeyVerify()" />
                <input class="submit_01" type="button" value="反初始化" onclick="DInitBiokey()" />
                <b>|</b>
                <input class="submit_01" type="button" value="人脸识别" onclick="FaceDetect()" />
                <input class="submit_01" type="button" value="人证比对" onclick="VerifyFaceDetect()" />
                <br />
                <input class="submit_01" type="button" value="启动二代证阅读" onclick="StartIDCard()" />
                <input class="submit_01" type="button" value="停止阅读" onclick="StopIDCard()" />
                <input class="submit_01" type="button" value="单次读取二代证" onclick="ReadIDCard()" />
                <img src=""  id="idcardimg" alt="二代证图像" width=20 height=20/>
                <b>|</b>
                <b>|</b>
                <input class="submit_01" type="button" value="启动磁条卡阅读" onclick="StartMagCard()" />
                <input class="submit_01" type="button" value="停止阅读" onclick="StopMagCard()" />
                <b>|</b>
                <input class="submit_01" type="button" value="启动深圳通阅读" onclick="StartShenZhenTongCard()" />
                <input class="submit_01" type="button" value="停止阅读" onclick="StopShenZhenTongCard()" />
                <br />
                <input type="text" id="message" size = "195"/>
                <input type="text" id="idcard" size = "195"/>
                <input type="text" id="biokey" size = "195"/>
                <input type="text" id="reader" size = "195"/>
                <input type="text" id="mag" size = "195"/>
                <input type="text" id="shenzhentong" size = "195"/>
                </div>
            </td>
        </tr>
        <div class="line1">
    
            文件:<input id="file" type="file" name="file"/>
            <button id="upload" onclick="upPic()">上传图片</button>
        </div>
        <div style="text-align: right;">
            <input class="submit_01" type="button" id="scan" value="拍照" style="border:none;padding:8px 25px;background-color:#43cd6e;color:#fff;font-size:16px;" />
            <input class="submit_01" type="button" value="仅身份证" onclick="only_idcar()" style="border:none;padding:8px 5px;background-color:#ccc;font-size:16px;"/>
            <input class="submit_01" type="button" value="仅拍头像" onclick="only_avator()" style="border:none;padding:8px 5px;background-color:#ccc;font-size:16px;"/>
            <input class="submit_01" type="button" value="清空表格" onclick="rescan()" style="border:none;padding:8px 9px;background-color:#ccc;font-size:16px;margin-left:6px;"/>
            <input class="submit_01" type="button" value="刷新网页" onclick="refresh()" style="border:none;padding:8px 9px;background-color:#ccc;font-size:16px;margin-left:53px;"/>
           
            
        </div>
        <div style="margin:30px 0 0 20px;float:right;">
        <input style="margin-right:25px;background-color:#28a3ef;border:none;color:#fff;padding:12px 7px;font-size:16px;" 
        class="btn" id="btnPrint" type="button" value="保存并打印" onclick="preview()" />
        <button style="background-color:#28a3ef;border:none;color:#fff;padding:12px 15px;font-size:16px;" onclick="save_member()">保存</button>
        <button style="background-color:#28a3ef;border:none;color:#fff;padding:12px 15px;font-size:16px;" onclick="print()">仅打印</button>
    </div>

    </div>
    <div id="table_box" style="width:23cm;float:left;">
        <form id="user_info">
        <table border="0" class="print_table" style="width:23cm;margin-left:20px;border-collapse:collapse;">
            
          <tr style="height:60px;border:1px solid transparent;">
            <td colspan="9" style="text-align:center;padding-left:2px;font-size:28px !important;border:1px solid transparent;">
                <span style="font-size:28px;font-weight:600;">{$info.title}</span>
            </td>
          </tr>

          <tr style="border:1px solid transparent;border-bottom:1px solid #000;">
          </tr>
        <tr class="border-none" style="height:36px;border:1px solid transparent;border-bottom:1px solid #000;">
                
                <td style="border:1px solid transparent;font-size:16px;border-bottom:1px solid #000;font-size:16px;font-size:22px;" colspan="3">序列号：<input class="serial"  name="serial" value="{$serial}" style="border:none;font-size:16px;padding-bottom:2px;font-family:'宋体','Arial Narrow';font-size:24px;"/></td>
                <td style="border:1px solid transparent;font-size:16px;border-bottom:1px solid #000;border-collapse:collapse;font-size:24px;" colspan="6">座号:{$serial_num}</td>
              </tr>
          <tr style="height:60px;">
            <td width="120px;" style="text-align:center;padding-left:2px;font-size:20px !important;border:1px solid #000;">姓名</td>
            <td  style="padding-left:10px;font-size:20px !important;border:1px solid #000;">
                <input type="text" name="name" value="" style="border:none;width:90%;font-size:22px;font-family:'宋体','Arial Narrow';"/>
            </td>
            <td width="120px;"  style="text-align: center;font-size:20px !important;border:1px solid #000;border-top:1px solid #000">身份证<div>号码</div></td>
            <td id="card_num" style="padding-left:10px;font-size:20px !important;border:1px solid #000;border-top:1px solid #000">
                <input type="text" name="card_num" value="" style="border:none;width:90%;font-size:22px;font-family:'宋体','Arial Narrow';"/>
            </td>
            <input type="hidden" name="avator" />
            <td rowspan="2" id="avator" style="width:4cm;height:5.6cm;text-align:center;vertical-align:middle;border:1px solid #000;">
                相片
            </td>
          </tr>
          <tr>
            
            <td width="100px" style="text-align: center;font-size:20px !important;border:1px solid #000;border-top:1px solid transparent">所属驾校</td>
        
            <td colspan="3" style="padding:10px 0 10px 10px;font-size:20px !important;border:1px solid #000;border-top:1px solid transparent;">
                 
                {volist name="school" id="vo" key="k"}
                    <div style="margin-bottom:10px;line-height: 25px;vertical-align: middle;display: inline-block;margin-right: 30px;">
                        <input class="schoolItem"  style="display: none;" type="radio" name="school" data-k="{$k}" id="schoolItem{$k}" value="{$vo.name}" />
                        
                        <span style="font-size:22px;">{$vo['name']}</span>
                        <div for="schoolItem{$k}" id="schoolLabel{$k}" data-k="{$k}" class="schoolLabel" style="background-color: #FFF; border: 1px solid #000;height:20px !important;width:20px !important;display: inline-block;">
                        </div>
                        
                    </div>
                 {/volist}
            </td>
            <td></td>
          </tr>
          <tr style="height: 60px">
            <td width="120px;" style="text-align: center;font-size:20px !important;border:1px solid #000;border-top:1px solid transparent">申请车型</td>
            <td colspan="4"  style="padding:0 10px;font-size:20px !important;border:1px solid #000;border-top:1px solid transparent">
             {volist name="card_type" id="vo" key="k"}
                    {if condition="$vo.isdefault eq 1"}
                        <Span style="float:left;">{$vo.name}</span><input class="mycheck" style="display:none;" checked="checked" type="radio" name="car_type" data-k="{$k}" id="mycheck{$k}" value="{$vo.id}" />
                        <div for="mycheck{$k}" id="label{$k}" class="card_type" style="background-color: #FFF; border: 1px solid #000;height:20px;width:20px;
                    display: inline-block; float:left; margin: 5px 25px 0 2px;"><img src='__STATIC__/images/check.png' style="height:18px;width:18px;padding:0;margin:0 0 1px 0px;"/></div>
                    {else /}
                        <Span style="float:left; font-size: 22px;">{$vo.name}</span><input class="mycheck" style="display:none;" type="radio" name="car_type" data-k="{$k}" id="mycheck{$k}" value="{$vo.id}" />
                        <div for="mycheck{$k}" id="label{$k}" class="card_type" style="background-color: #FFF; border: 1px solid #000;height:20px !important;width:20px !important;
                    display: inline-block; float:left; margin: 5px 25px 0 2px;"></div>
                    {/if}
                {/volist}
            </td>
          </tr>
           <tr>
            <!-- <td width="120px;" style="text-align: center;font-size:20px !important;border:1px solid #000;border-top:1px solid transparent">培训路口</td> -->
            <td colspan="5" style="padding:15px 25px 40px 15px;font-size:20px !important;border:1px solid #000;">
                <div style="display:line-block; float:left;font-size: 22px">场次：</div>
                {volist name="times" id="vo" key="k"}
                    <div for="times{$k}" id="timeLabel{$k}" class="timeLabel" style="background-color: #FFF; border: 1px solid #000;height:20px !important;width:20px !important;display: inline-block; float:left; margin: 5px 0px 0 2px;font-size: 22px;"></div>
                        <Span style="float:left;margin-right: 30px;font-size: 24px;">{$vo}</span><input class="times" style="display:none;" type="radio" name="times" data-k="{$k}" id="times{$k}" value="{$vo}" />
                        
                {/volist}
            <td>
          </tr>
        </table>
        <div style="padding: 0 20px;">
            <div style="font-weight: 400;font-size: 28px;margin-top: 10px;">一、交通安全文明驾驶常识教育</div>
            <div style="font-size:22px;line-height: 36px;">1、车辆起步前，驾驶人应对车辆周围交通情况进行观察，确认安全时再开
    始起步;2、行车中从其他道路汇入车流前，应注意观察侧后方车辆的动态;3、
    驾驶车辆进入交叉路口前，应降低行驶速度注意观察，确认安全;4、车辆通过
    学校和小区应注意观察标志标线，低速行驶，不要鸣喇叭;5、车辆不得在高速
    公路匝道上掉头、倒车;6、驾驶机动车经过漫水路、漫水桥时，应停车察明水
    情，确认安全后再通过;7、行车中遇儿童时，应减速慢行，必要时停车避让;8、
    行车中遇抢救伤员的救护车从本车道逆向驶来时，须减速或靠边停车让行;9、
    车辆驶近人行横道时，先减速注意观察行人、非机动车动态，确认安全后再通过;10、机动车通过没有交通信号的交叉路口时减速慢行。</div>
            <div style="font-weight: 400;font-size: 24px;margin-top: 10px;">二、交通事故案例警示教育</div>
            <div style="font-size:22px;margin-bottom: 5px; ">1、观看交通事故案例警示教育宣传片;</div>
            <div style="font-size:22px;margin-bottom: 5px;">2、浏览交通安全橱窗(宣传栏);</div>
            <div style="font-size:22px;margin-bottom: 5px;">3、阅读交通事故案例宣传资。</div>
            <div style="margin-top: 20px"><text style="margin-right: 20px;font-size:22px;">三、培训结果:</text>
                <text  style="font-size:22px;">合格</text><div style="line-height: 30px;vertical-align: middle;display: inline-block;margin-right: 50px;margin-left: 15px;">
                        <div for="" id="resultLabel1" data-value="合格" class="resultLabel" style="background-color: #FFF; border: 1px solid #000;height:16px !important;width:20px !important;display: inline-block;font-size:22px;">
                            
                        </div>
                    </div> 

                <text  style="font-size:22px;">不合格</text><div style="line-height: 30px;vertical-align: middle;display: inline-block;margin-right: 50px;margin-left: 15px;">
                    <div for="" id="resultLabel2" data-value="不合格" class="resultLabel" style="background-color: #FFF; border: 1px solid #000;height:20px !important;width:20px !important;display: inline-block;font-size:22px;">
                        
                    </div>
                </div>
                <input type="text" name="finish" style="display: none" class="result" value="">
            </div>
            <div style="font-size:22px;">四、学员培训合格后请把表格拍照片上传到钦州驾考通。</div>
        </div>
      </form>
      <!-- <img src='__STATIC__/images/code01.jpg' style="width: 180px;height: 180px;margin-right: 50px"><img src='__STATIC__/images/code02.jpg' style="width: 180px;height: 180px"></div>
 -->    </div>
    <div id="mask">
        <div id="msg">正在识别身份证或上传照片，请稍等......</div>
    </div>
    <script>
        const viewList = [
            "http://127.0.0.1:38088/video=stream&camidx=0",
            "http://127.0.0.1:38088/video=stream&camidx=1",
        ]

        // 打开摄像头
        const openCamera = index =>{
            var containerId = '';
            if(index==0){
                containerId = "firstVideo";
            }else if(index==1){
                containerId = "secondVideo";
            }


            oldViewSrc = document.getElementById(containerId).src;
            oldViewIndex = oldViewSrc.slice(-1)
            
            // 1.关闭
            if (String(index) == String(oldViewIndex)){
                return
            }else{
                let data = { "camidx": String(oldViewIndex) }
                $.post("http://127.0.0.1:38088/video=close", JSON.stringify(data), res=>{
                    if (res.code == "0"){
                        console.log("已原关闭，正在打开新视频");
                        document.getElementById(containerId).src = viewList[index];
                        console.log("打开成功");
                    }else{
                        console.log("关闭视频失败");
                    }
                })
            }
        }
        GetResolution(0);//获取主摄像头分辨率
        GetResolution(1);//获取副摄像头分辨率
        openAll(); //打开所有摄像头

        function openAll(){
            openCamera(0);
            openCamera(1);
        }
        // 点击拍照
        document.getElementById("scan").onclick = ()=>{
            scan(0);
        }
        //拍照处理
        function scan(DevIndex = 0){
            rescan();//清空上一个人的数据
            var deviceName = '';
            var resImg = '';
            if(DevIndex == 0){
                deviceName = "firstVideo";
                resImg = "firstResImg";
            }else if(DevIndex == 1){
                deviceName = "secondVideo";
                resImg = "secondResImg";
            }
            // 获取到摄像头信息
            oldViewSrc = document.getElementById(deviceName).src;
            oldViewIndex = oldViewSrc.slice(-1)
           
            // 拍照接口参数
            let data = {
                "filepath": "base64",
                "camidx": String(oldViewIndex),
            }
            if(DevIndex == 1){
                var content = showtime();
                content = content + " 道路交通安全警示教育照片";
                var watermark = {"pos":"1","content":content,"transparency":"250","fontsize":"38","font":"微软雅黑","color":"red"};
                data.watermark = watermark;
            }
            $.post("http://127.0.0.1:38088/video=grabimage", JSON.stringify(data), res=>{
                if(res.code == "0"){
                    var base64Data = "data:image/jpeg;base64," + res.photoBase64;
                    document.getElementById(resImg).src = base64Data;
                    if(DevIndex == 0){
                        scan(1);
                        get_info(res.photoBase64);
                    }else if(DevIndex == 1){
                        //保存用户头像信息到本地
                        ajax_upload(res.photoBase64);
                    }
                }else{
                    console.log("拍照失败，error: " + res);
                }

            })
        }



        //仅拍身份证，主摄像头拍
        function only_idcar(){
            // 获取到摄像头信息
            oldViewSrc = document.getElementById("firstVideo").src;
            oldViewIndex = oldViewSrc.slice(-1)
            // 拍照接口参数
            let data = {
                "filepath": "base64",
                "camidx": String(oldViewIndex)
            }
            $.post("http://127.0.0.1:38088/video=grabimage", JSON.stringify(data), res=>{
                if(res.code == "0"){
                    var base64Data = "data:image/jpeg;base64," + res.photoBase64;
                    document.getElementById("firstResImg").src = base64Data;
                    get_info(res.photoBase64);
                }else{
                    console.log("拍照失败，error: " + res);
                }

            })
        }
        //仅拍头像 ,头像是副摄像头拍
        function only_avator(){
            // 获取到摄像头信息
            oldViewSrc = document.getElementById("secondVideo").src;
            oldViewIndex = oldViewSrc.slice(-1)
            var filePath = '';
            var content = showtime();
            var watermark = {"pos":"1","content":content,"transparency":"250","fontsize":"45","font":"微软雅黑","color":"red"};
            //拍照接口参数
            let data = {
                "filepath": "base64",
                "camidx": String(oldViewIndex),
                "watermark":watermark
            }

            $.post("http://127.0.0.1:38088/video=grabimage", JSON.stringify(data), res=>{
                if(res.code == "0"){
                    var base64Data = "data:image/jpeg;base64," + res.photoBase64;
                    document.getElementById("secondResImg").src = base64Data;
                    ajax_upload(base64Data);
                }else{
                    console.log("拍照失败，error: " + res);
                }

            })
        }

        //获取分辨率数据
        function GetResolution(DevIndex=0)
        {
            var selectId = "";
            if(DevIndex == 0){
                selectId = "resolutionFirst";
            }else if(DevIndex == 1){
                selectId = "resolutionSecond";
            }
            document.getElementById(selectId).options.length = 0;
            var nMode = "MJPG";
            var params = "{\"camidx\":\"" + DevIndex + "\",\"mode\":\"" + nMode + "\"}"; 
            var url = "http://127.0.0.1:38088/device=getresolution";
        
            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: params,
                success: function (data) {
                    if(data.code == 0)
                    {
                        var select = document.getElementById(selectId);
                        //获取select下拉框下所有的选项
                        while(select.options.length > 0)
                        {
                            select.remove(i);
                        }
                        
                        var arrays = data.data.split("|");
                        for(var i=0; i<arrays.length; i++)
                        {
                            select.options.add(new Option(arrays[i], arrays[i])); 
                        }
                        if(DevIndex == 0){
                            SetFirstResolution();
                        }        
                        else if(DevIndex == 1){
                            SetSecondResolution();
                        }
                        
                    }
                    else
                    {
                        var date = new Date().toLocaleString();
                        console.log(date + '\t' + "分辨率数据失败");
                    }
                }
            }); 
        }

        //设置主摄像头分辨率
        function SetFirstResolution()
        {   

            var DevIndex = 0;
            var nMode = "MJPG";
            var index_resolution = 5; //要设置为第几项

            $("#resolutionFirst option").eq(index_resolution).attr("selected","selected");

            var select_resolution = document.getElementById("resolutionFirst");  
            var text_resolution = select_resolution.options[index_resolution].text
            var splits = text_resolution.split("*");
            
            var params = "{\"camidx\":\"" + DevIndex + "\",\"mode\":\"" + nMode + "\",\"width\":\"" + splits[0] + "\",\"height\":\"" + splits[1] + "\"}"; 
            var url = "http://127.0.0.1:38088/device=setresolution";
            
                $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: params,
                success: function (data) {
                    if(data.code == 0)
                    {
                        var date = new Date().toLocaleString();
                        console.log(date + '\t' + "分辨率设置成功" );
                    }
                    else
                    {
                        var date = new Date().toLocaleString();
                         console.log(date + '\t' + "分辨率设置失败");
                    }
                }
            }); 
        }

        //设置副摄像头分辨率
        function SetSecondResolution()
        {   

            var DevIndex = 1;
            var nMode = "MJPG";
            var index_resolution = 4; //要设置为第几项

            $("#resolutionSecond option").eq(index_resolution).attr("selected","selected");

            var select_resolution = document.getElementById("resolutionSecond");  
            var text_resolution = select_resolution.options[index_resolution].text
            var splits = text_resolution.split("*");
            
            var params = "{\"camidx\":\"" + DevIndex + "\",\"mode\":\"" + nMode + "\",\"width\":\"" + splits[0] + "\",\"height\":\"" + splits[1] + "\"}"; 
            var url = "http://127.0.0.1:38088/device=setresolution";
            
                $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: params,
                success: function (data) {
                    if(data.code == 0)
                    {
                        var date = new Date().toLocaleString();
                        console.log(date + '\t' + "分辨率设置成功" );
                    }
                    else
                    {
                        var date = new Date().toLocaleString();
                         console.log(date + '\t' + "分辨率设置失败");
                    }
                }
            }); 
        }

        //关闭摄像头
        function CloseCamera(DevIndex = 0)
        {   
            var isIE = false;
            var deviceName = '';
            if(DevIndex == 0){
                deviceName = "firstVideo";
            }else if(DevIndex == 1){
                deviceName = "secondVideo";
            }
            if(isIE)
            {
                showVideoOcx.StopPreview();
            }   
            else
            {
                var params = "{\"camidx\":\"" + DevIndex + "\"}"; 
                var url = "http://127.0.0.1:38088/video=close";
            
                $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                data: params,
                success: function (data) {
                    if(data.code == 0)
                    {
                        var date = new Date().toLocaleString();
                        document.getElementById(deviceName).src = "";
                        if(DevIndex == 0){
                            CloseCamera(1); //关闭第二个摄像头
                        }    
                    }
                    else
                    {
                        var date = new Date().toLocaleString();
                        console.log(date + '\t' + "关闭视频失败");
                    }
                }
                }); 
            }
            
        }
        function ajax_upload(base64){
            $("#mask").show();
            $.ajax({
                    type: "POST",
                    url:"{:Url('Upload/base64')}",
                    data:{'file':base64},
                    async: true,
                    error: function(request) {
                        alert("上传头像照片失败，请按\"仅拍头像\"重拍学员头像");
                    },
                    success: function(data) {
                        data.replace(/\\/g, "");
                        data = data.replace("public/", "");
                        $("#user_info input[name='avator']").val(data);
                        $("#avator").html("<img style='height:5.6cm;width:4cm;' src='/"+data+"' />");
                        $("#mask").hide();
                    }
            });
        }
        //ajax返回身份证信息
        function get_info(base64)
        {
            $.ajax({
                    cache: true,
                    type: "POST",
                    url:"{:Url('Baidu/get_idcar_info_by_base64')}",
                    data:{'data':base64},
                    async: true,  //true 异步，false同步，同步时浏览器将被锁死
                    timeout:43000,//设置超时时间，建议设置比php最大执行时间小
                    beforeSend:function(){
                        
                    },
                    error: function(request) {
                        alert("请求身份证信息超时，请重拍信息");
                        $("#mask").hide();
                    },
                    success: function(data) {
                        $("#mask").hide();
                        var obj = eval('(' + data + ')');
                            //console.log(obj);
                            /*以下判断条件均由百度接口返回数据作为依据*/
                            if(obj.error_code!=""&&obj.error_code!=null&&obj.error_code!="undentify")
                            {
                                $("#mask").hide();
                                alert("无法识别身份证信息，请重拍或手动输入");
                            }
                            else if(obj.err!="undentify"&&obj.err!=""&&obj.err!=null)  //该错误由后台curl提供
                            {
                                $("#mask").hide();
                                alert("无法识别身份证信息，curl请求错误，请重拍或手动输入");
                            }
                            else if(obj.words_result=="undentify"||obj.words_result==""||obj.words_result==null)
                            {
                                $("#mask").hide();
                                alert("无法识别身份证信息，请重拍或手动输入");
                            }
                            else{
                                $("#user_info input[name='name']").val(obj.words_result.姓名.words);
                                $("#user_info input[name='sex']").val(obj.words_result.性别.words);
                                $("#user_info input[name='card_num']").val(obj.words_result.公民身份号码.words);
                                $("#user_info textarea[name='address']").val(obj.words_result.住址.words);
                                $("#mask").hide();
                            }
                            $("#mask").hide();
                    }
            });
        }


        //处理select 跟checkbox的信息能被打印出来
        function bindData(){
            //搞定 type=text, 同时如果checkbox,radio,select>option的值有变化, 也绑定一下, 这里忽略button
            $("input,select option").each(function(){
                $(this).attr('value',$(this).val());
            });
            
            //搞定 type=checkbox,type=radio 选中状态
            $("input[type='checkbox'],input[type='radio']").each(function(){
                if($(this).attr('checked'))
                    $(this).attr('checked',true);
                else
                    $(this).removeAttr('checked');
            });
            
            //搞定select选中状态
            $("select option").each(function(){
                if($(this).attr('selected'))
                    $(this).attr('selected',true);
                else
                    $(this).removeAttr('selected');
            });
            
            //搞定 textarea
            $("textarea").each(function(){
                $(this).html($(this).val());
            });
            
        }
        //保存并打印
        function preview()         
        {   
            bindData();
            var save=save_member_print(); //保存用户信息
            if(save)
            {

                bindData();
                $("#table_box").jqprint(); //打印插件
            }
        }
        //仅打印
        function print()         
        {  
            bindData();
            $("#table_box").jqprint(); //打印插件
        }
        function checkData(){
                    var name=$("#user_info input[name='name']").val();
                /*  var sex=$("#user_info input[name='sex']").val();*/
                    var card_num=$("#user_info input[name='card_num']").val();
                    var school=$("input[name='school']:checked").val();
                /*  var mobile=$("#user_info input[name='mobile']").val();*/
                    var car_type=$("#user_info input[name='card_type']").val();
                    var time =$("input[name='times']:checked").val();
                    var result =$(".result").val();
                    if(!/^([\u4E00-\u9FFF]|\w){2,11}$/.test(name))
                    {
                        alert("姓名格式不正确");
                        $("#user_info input[name='name']").focus();
                        return false;
                    }
                    if(card_num==null||card_num==""){
                        alert("身份证信息不能为空，请手动填写");
                        $("#user_info input[name='card_num']").focus();
                        return false;
                    }
                    if(school==null||school==""){
                        alert("驾校名称不能为空，请选择");
                        //$("#user_info input[name='school']").focus();
                        return false;
                    }
                    if(time==null||time==""){
                        alert("时间段不能为空，请选择");
                        //$("#user_info input[name='school']").focus();
                        return false;
                    }
                    if(result==null||result==""){
                        alert("请选择培训结果");
                        //$("#user_info input[name='school']").focus();
                        return false;
                    }
                    return true;
                }
        //保存用户信息但不清空数据
        function save_member_print(){
            if(!checkData()){
                        return;
                    }
           
                $.ajax({
                        type: "POST",
                        url:"{:Url('Member/add')}",
                        data:$("#user_info").serialize(),
                        async: false,
                        error: function(request) {
                            alert("系统繁忙，请稍后重试...");
                        },
                        success: function(data) {
                            if(data.code == 0){
                                alert("保存信息成功");
                            }else{
                                alert(data.msg ? data.msg : "保存信息失败");
                            }
                            
                        }
                });
                return true;
            
        }
        //保存用户信息并清空数据
        function save_member(){

            if(!checkData()){
                        return;
                    }
                $.ajax({
                        type: "POST",
                        url:"{:Url('Member/add')}",
                        data:$("#user_info").serialize(),
                        async: false,
                        error: function(request) {
                            alert("系统繁忙，请稍后重试...");
                        },
                        success: function(data) {
                            if(data.code == 0){
                                alert("保存信息成功");
                                rescan(); //清空数据，开始下一个用户。
                            }else{
                                alert(data.msg ? data.msg : "保存信息失败");
                            }
                           
                        }
                });
            
        }

        //驾校选择处理
        function choose(val){
            var school=$("#school option:selected").text();
            $(".school").html(school);
        }

        //申请车型勾选处理
        $(document).ready(function () {
            $("#scansize").val("small");
            //选择申请车型
                var img="<img src='__STATIC__/images/check.png' style='height:18px;width:18px;padding:0;margin:3px 0 1px 0px;' />";
                $(".mycheck").change(function() {
                    var k=$(this).attr("data-k");
                    $(".card_type").html("");
                    $("#label"+k).html(img);
                });
                //防止label for 不起效
                $(".card_type").click(function(e){
                    e.preventDefault(); 
                    $("#"+$(this).attr("for")).click().change(); 
                });
                //驾校选择
                $(".schoolItem").change(function() {
                    var k=$(this).attr("data-k");
                    $(".schoolLabel").html("");
                    $("#schoolLabel"+k).html(img);
                });
                //防止label for 不起效
                $(".schoolLabel").click(function(e){
                    e.preventDefault(); 
                    $("#"+$(this).attr("for")).click().change(); 
                });
                //时间段选择
                $(".times").change(function() {
                    console.log(1111);
                    var k=$(this).attr("data-k");
                    $(".timeLabel").html("");
                    $("#timeLabel"+k).html(img);
                });
                //防止label for 不起效
                $(".timeLabel").click(function(e){
                    e.preventDefault(); 
                    $("#"+$(this).attr("for")).click().change(); 
                });
                $(".resultLabel").click(function(){
                    $(".resultLabel").html("");
                    var val=$(this).attr("data-value");
                    $(this).html(img);
                    $(".result").val(val);
                });
            $("#scan").click(function(){
                
            });
        });

        //重拍即清空数据
        function rescan(){
            //清空缩略图列表
            // document.getElementById("firstResImg").src = "";
            // document.getElementById("secondResImg").src = "";
            //清空用户信息
            $("#user_info input[name='name']").val("");
            $("#user_info input[name='sex']").val("");
            $("#user_info input[name='card_num']").val("");
            $("#user_info input[name='mobile']").val("");
            $("#user_info textarea[name='address']").val("");
            $(".serial").val("");
            $("#avator").html("尚未拍照");
            //向服务器请求新的序列号
            $.ajax({
                type: "get",
                url:"{:Url('Member/ajax_code')}",
                data:{},
                async: false,
                error: function(request) {
                    alert("服务器无法提供给一个正确的序列号，请刷新网页");
                },
                success: function(data) {
                    
                    $(".serial").val(data);
                }
            });
        }

        //刷新网页
        function refresh(){
            window.location.reload();
        }
        //获取时间格式
        function showtime() {

            var nowdate = new Date();

            var year = nowdate.getFullYear(),

                month = nowdate.getMonth() + 1,

                date = nowdate.getDate(),

                day = nowdate.getDay(),

                week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],

                h = nowdate.getHours(),

                m = nowdate.getMinutes(),

                s = nowdate.getSeconds(),

                h = checkTime(h),

                m = checkTime(m),

                s = checkTime(s);

            return year + "年" + month + "月" + date + "日" + " "+ week[day] + " " + h +":" + m + ":" + s;

        }
        var checkTime = function (i) {
            if (i < 10) {
                i = "0" + i;
            }
            return i;
        }
    </script>
</body>
</html>